from pyecharts.charts import Pie
import pyecharts.options as opts
with open('data.csv', 'r', encoding='utf-8') as f:
    lines=f.readlines()
    # lines = lines.split('\n')
    lines=lines[1:51]
    lines=[i.split(',') for i in lines]
    num=[0,0,0,0,0,0]
    lad=['0-10万','10-20万','20-30万','30-40万','40-50万','50-60万']
    for i in range(len(lines)):
        price=lines[i][3].strip()
        selecount=int(lines[i][4].strip())
        prices=price.split('-')
        min_price=float(prices[0])
        max_price=float(prices[1].replace('万', ''))
        mid_price=(min_price+max_price)/2
        l=int(mid_price/10)
        # print(l)
        match l:
            case 0:
                num[0] += selecount
            case 1:
                num[1] += selecount
            case 2:
                num[2]+=selecount
            case 3:
                num[3] += selecount
            case 4:
                num[4] += selecount
            case 5:
                num[5] += selecount
                break

pie = (
    Pie(init_opts=opts.InitOpts(width='1000px', height='500px'))
    .add(series_name='', data_pair=[(i, j) for i, j in zip(lad, num)])
    .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{c}"))
)

pie.render('PriceData.html')